<template>
	<view>
		<uni-filter :filterData="filterData" :defaultSelected="filterDropdownValue" @sort="sortValue" @confirm="confirm"></uni-filter>
		<view style="margin-top: 130rpx;"></view>	
	
		<view class="changfang">
			<uni-item v-if="!parks" :item=item v-for="(item,index) in new_workshop" :key="item.id"></uni-item>
			
			<uni-item2 v-if="parks" :item=item v-for="(item,index) in new_workshop" :key="item.id"></uni-item2>
		</view>
		<uni-load-more :status="more" color="#000000" @clickLoadMore="getFactorys"></uni-load-more>
	<uni-footer></uni-footer>
	</view>
</template>

<script>


	export default {
		data() {
			return {
				more: "more",
				page: 1,
				new_workshop: [],
				loadingText: "正在加载...",
				filterDropdownValue: [],
				filterData: [],
				form:{},
				indexArr:'',
				valueArr:'',
				parks:'',
				tejia:'',
				ershou:'',
				search_key:'',
				sort:false,
			};
		},
			onShareAppMessage() {},
		filters: {
			outData(value) {
				console.log('outdata',value)
				return JSON.stringify(value);
			}
		},
		onPullDownRefresh() {
		        //监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
			this.page=1
			this.new_workshop=[]
			this.more='more'
			this.form['parks']=this.parks
			this.form['tejia']=this.tejia 
			this.form['ershou']=this.ershou 
			this.form['search_key']=this.search_key 
			this.form['sort']=this.sort 
			this.getFactorys()
		},

		methods: {
			confirm({
				index,
				value
			}) {
				this.indexArr = index;
				this.valueArr = value;
				this.page=1
				this.new_workshop=[]
				this.more='more'
				let form={}
				for (let i in index)
				{
					for(let y in index[i]){
						 console.log(this.filterData[i].submenu[y])
						form[this.filterData[i].submenu[y].slug]=''
						 for(let x in index[i][y]){
							 console.log(131)
							 console.log(this.filterData[i].submenu[y].submenu[x])
							form[this.filterData[i].submenu[y].slug]=this.valueArr[i][y][x]
						} 
					}
				}
				this.form=form
				console.log(this.parks)
				this.form['parks']=this.parks 
				this.form['tejia']=this.tejia 
				this.form['ershou']=this.ershou 
							this.form['search_key']=this.search_key 
				this.form['sort']=this.sort 
				console.log(this.form['parks'])
				this.getFactorys()
			},
			sortValue(sort){
				this.sort=sort
				this.page=1
				this.new_workshop=[]
				this.more='more'

		
				this.getFactorys()
			},
			getFactorys() {
				if (this.more == 'noMore') {
					return
				}
				console.log('form1',this.form)
				this.form=Object.assign(this.form,{page:this.page,sort:this.sort})
				console.log('form',this.form)
				console.log(this.form)
				this.more = "loading"
				this.$api.getFactorys(this.form).then(res => {
					this.new_workshop = this.new_workshop.concat(res.data);
					console.log(this.new_workshop)
					 uni.stopPullDownRefresh(); 
					this.page = this.page + 1
					if (!res.links.next) {
						this.more = 'noMore'
					} else {
						this.more = "more"
					}

				})
			}
		},

		onLoad: function() {
			console.log('onload')
			
			this.$api.getFactorysCondition().then(res => {
				console.log(res.data)
				this.filterData = res.data;
			})
			if(!getApp().globalData.is_park&&!getApp().globalData.tejia&&!getApp().globalData.ershou&&!getApp().globalData.search_key){
						this.getFactorys()
			}
	
		},
		onTabItemTap:function(){
			console.log('onTabItemTap')

		},
		onShow:function(){
		 	// #ifdef MP-TOUTIAO
					
				/* if(!token){
					uni.reLaunch({
						url:"/pages/login/login"
					})
				} */
				// #endif 
				
			console.log('onshow')
			console.log(getApp().globalData.is_park)
			console.log(getApp().globalData.tejia)
	
			if(getApp().globalData.is_park){
				this.page=1
				this.new_workshop=[]
				this.more='more',
				this.form={}
				this.form['parks']=getApp().globalData.is_park
				this.parks=getApp().globalData.is_park
				uni.setNavigationBarTitle({
					title:getApp().globalData.park_name
				})
				this.getFactorys()
		
				getApp().globalData.is_park=null
				getApp().globalData.park_name=null
			}else if(getApp().globalData.tejia){
				this.page=1
				this.new_workshop=[]
				this.more='more',
				this.form={}
				this.form['tejia']=getApp().globalData.tejia
				this.tejia=getApp().globalData.tejia
				uni.setNavigationBarTitle({
					title:'特价厂房'
				})
				this.getFactorys()
			
				getApp().globalData.tejia=null
			
			}else if(getApp().globalData.search_key){
				this.page=1
				this.new_workshop=[]
				this.more='more',
				this.form={}
				this.form['search_key']=getApp().globalData.search_key
				this.search_key=getApp().globalData.search_key
				uni.setNavigationBarTitle({
					title:'搜索:'+getApp().globalData.search_key
				})
				this.getFactorys()
				getApp().globalData.search_key=null
			
			}else if(getApp().globalData.ershou){
				this.page=1
				this.new_workshop=[]
				this.more='more',
				this.form={}
				this.form['ershou']=getApp().globalData.ershou
				
				this.ershou=getApp().globalData.ershou
				uni.setNavigationBarTitle({
					title:'二手厂房'
				})
				this.getFactorys()
			
				getApp().globalData.ershou=null
			
			}
			else if(getApp().globalData.is_park===null||getApp().globalData.tejia===null||getApp().globalData.ershou===null||getApp().globalData.search_key===null){

				this.page=1
				this.new_workshop=[]
				uni.setNavigationBarTitle({
					title:'我要买厂'
				})
				this.more='more',
				this.parks=''
				this.form={}
				this.getFactorys()
				getApp().globalData.is_park=""
				getApp().globalData.tejia=''
				getApp().globalData.ershou=''
				getApp().globalData.search_key=''
			}
		
		}
	}
</script>
<style  >
	page{
	//	background-color: #f3f3f3;
	}
</style>
<style scoped lang="scss">
	.changfang{
		padding-left: 26rpx;
		padding-right: 26rpx;
	}
</style>
